import translate from 'google-translate-open-api';

import translates from './translate';
import language from '../file/language';
import languageList from '../file/languageList';

class google implements translates {
  async trans(lan: language, value: string): Promise<any> {
    let from = this.getFormTo(lan.getRawLanguage());
    let to = this.getFormTo(lan.getNewLanguage());
    let result = await translate(value, {
      tld: 'cn',
      from: from,
      to: to
    });
    let data = result.data;
    console.log(result);
    
    return data;
  }
  private getFormTo(language: languageList): string {
    switch (language) {
      case languageList['Chinese-s']: {
        return 'zh-CN';
      }
      case languageList['Chinese-t']: {
        return 'zh-CN';
      }
      case languageList['France']: {
        return 'fr';
      }
      case languageList['German']: {
        return 'de';
      }
      case languageList['English']: {
        return 'en';
      }
    }
  }
}

const trans = new google();
export default trans;
